package factory.simpleFactory;

interface Car {
    void name();
}

class Bus implements Car {
    @Override
    public void name() {
        System.out.println("Car");
    }
}

class Vehicle implements Car{
    @Override
    public void name() {
        System.out.println("Vehicle");
    }
}

class CarFactory {
    public static Car getCar(String car) {
        if (car.equals("Bus")) {
            return new Bus();
        } else if (car.equals("Vehicle")) {
            return new Vehicle();
        } else {
            return null;
        }
    }
}

public class Consumer {
    public static void main(String[] args) {
        Car bus = CarFactory.getCar("Bus");
        Car vehicle = CarFactory.getCar("Vehicle");
        if (bus != null) {
            bus.name();         //Car
        }
        if (vehicle != null) {
            vehicle.name();     //Vehicle
        }
    }
}